// TransformDoc.cpp : implementation of the CTransformDoc class
//

#include "stdafx.h"
#include "Transform.h"
#include "TransformDoc.h"
#include "GViewer.h"
#include "Global.h"
#include "TimelineView.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CTransformDoc

IMPLEMENT_DYNCREATE(CTransformDoc, CDocument)

BEGIN_MESSAGE_MAP(CTransformDoc, CDocument)
END_MESSAGE_MAP()


// CTransformDoc construction/destruction

CTransformDoc::CTransformDoc()
: m_pMainFrame(NULL)
{
	// TODO: add one-time construction code here

}

CTransformDoc::~CTransformDoc()
{
}

BOOL CTransformDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}

void CTransformDoc::Update()
{

}


// CTransformDoc serialization

void CTransformDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}


// CTransformDoc diagnostics

#ifdef _DEBUG
void CTransformDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CTransformDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

bool CTransformDoc::Save(LPCTSTR szXMLPath)
{
	m_oXMLParser.SetDoc(_T(""));
	CTimeline* pTimeline = m_oSKInfo.GetTimeline();
	pTimeline->OnWrite(&m_oXMLParser);
	CString strDoc = m_oXMLParser.GetDoc();

	CStdioFile* pStdioFile = new CStdioFile();
	pStdioFile->Open(szXMLPath, CFile::modeCreate | CFile::modeWrite);
	pStdioFile->WriteString(strDoc);
	pStdioFile->Close();
	delete pStdioFile;
	pStdioFile = NULL;

	return true;
}

bool CTransformDoc::Load(LPCTSTR szXMLPath)
{
	m_oSKInfo.Reset();
	CSKGlobal::GetViewer()->Reset();

	CString strXML;
	CString strText = _T("");
	CStdioFile* pStdioFile = new CStdioFile();
	pStdioFile->Open(szXMLPath, CFile::typeText|CFile::modeRead);
	while (pStdioFile->ReadString(strText))
	{
		strXML += strText;
		strXML += _T("\r\n");
	}
	pStdioFile->Close();
	delete pStdioFile;
	pStdioFile = NULL;

	m_oXMLParser.SetDoc(strXML);

	CTimeline* pTimeline = m_oSKInfo.GetTimeline();
	pTimeline->OnRead(&m_oXMLParser);

	CSKGlobal::GetTimelineView()->UpdateView();

	return true;
}
// CTransformDoc commands
